<?
session_start();
$id = "";
if(isset($_GET['id'])) {
	$id = $_GET['id'];
}
$dialog_parent = "parent";
if(isset($_GET['in_call_panel'])) {
	$dialog_parent = "parent.parent";
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../../../webkit/utils/jquery.js"></script>
<script type="text/javascript" src="../../../webkit/utils/form.checker.js"></script>
<script type="text/javascript" src="../../../webkit/datepicker/WdatePicker.js"></script>
<link type="text/css" rel="stylesheet" href="../../page.css"/> 
<body  bgcolor="#f4f4f4" style="margin:0px;" scroll=no>

<form name=f> 
<hr size=1>
<table width=100% cellspacing=1 cellpadding=3 id="basic_info_table"> 
	<tr>
        <td align=right nowrap>客户姓名</td><td><input type='text' id="cust_name" class='input' check='not_empty' warning='客户姓名不能为空！' style="color:blue"></td>  
		<td align=right>客户性别</td><td><select id="cust_sex" class='input'><option value=1>男</option><option value=2>女</option></select></td>
	</tr>
	<tr>
        <td align=right>客户电话</td><td><input type='text' id="cust_tel" class='input' check='not_empty' warning='联系电话不能为空！' style="color:red"><img src='/webkit/portal/images/query.png' title='输入电话号码查询客户' style="cursor:hand" onclick="if($('#cust_tel').val()=='') {alert('请输入客户电话进行查询！')} else {init_customer($('#cust_tel').val())}"></td> 
		<td align=right>客户区域</td><td><input type='text' id="cust_addr" class='input' value=''></td>
	</tr>
	<tr>
		<td align=right>客户备注</td><td colspan=3><textarea style="width:500px;" rows=3 id="cust_desc"></textarea></td>
	</tr>
	<tr>
		<td align=right>服务号码</td><td><input type='text' id="call_tel" class='input' style="color:#3300cc" readonly></td>
		<td align=right>呼叫类型</td><td><select id="call_type" class='input'><option value='1'>呼入</option><option value='2'>呼出</option></select></td>
	</tr>
	<tr>
		<td align=right>呼叫结果</td><td><select id="call_result" class='input'><option value='1'>正常接通</option><option value='2'>无法接通</option><option value='3'>号码错误</option></select></td>
		<td align=right nowrap>业务类型</td><td><select id="biz_type" class='input'><option value='1'>业务咨询</option><option value='2'>产品定购</option><option value='3'>客户回访</option><option value='4'>投诉建议</option></select></td>
	</tr>
	<tr>
		<td align=right>沟通内容</td><td colspan=3><textarea style="width:500px;" rows=4 id="call_content"></textarea></td>
	</tr>
	<input type='hidden' id="agent_id" value="<?echo $_GET['agent_id']?>">
	<input type='hidden' id="call_time" value="<?echo date("Y-m-d H:i:s")?>">
	<input type='hidden' id="id" value="<?echo $id?>">
</form>	

<table width=100% cellspacing=1 cellpadding=3>
	<tr>
		<td align=center>
		<hr size=1>
		<input type="button" id="btn_save" class="button" value="保存信息" onclick="save()">　　<input type="button" class="button" value="关闭窗口" onclick="close_dlg()"></td>
	</tr>
</table>

<script type="text/javascript">
	var f = document.f;

	function close_dlg() {
		if(confirm('你尚未保存当前客户信息，确定要关闭吗？')) {
			<?echo  $dialog_parent?>.closeDlg()
		}
	}

	function save() { 
		if(FormChecker.doCheck(f)) {
			var params = {};
			var els = f.elements;
			for(var i=0; i<els.length; i++) {
				if(els[i].type == "button") continue;
				params[els[i].id] = els[i].value;
			}
			if(confirm('确定要保存客户信息吗？')) {
				$('#btn_save').attr('disabled', true);
				$('#btn_save').val('保存中..');
				$.post("client_query.php?action=<?echo $_GET['op']?>", params, function(data) {
					if(data.indexOf("ok") == 0) {
						alert("数据保存成功!");
						<?echo  $dialog_parent?>.refreshGrid();
						<?echo  $dialog_parent?>.closeDlg();
					} else {  
						alert(data);
					}
					$('#btn_save').attr('disabled', false);
					$('#btn_save').val('保存信息');
				});
			}
		}
	}; 

	
	function init_customer(tel) {
		$.get("client_query.php?action=get_customer&cust_tel="+tel, function(data){
			if(data == "new customer") {
				$('#cust_desc').val('提示：这是一个未登记的新客户，请补充相关信息');
			} else {
				eval("var row = "+data);
				for(var k in row) {
					$("#"+k).val(row[k]);
				}
			}
		})
	}

	function init_record(id) {
		$.get("client_query.php?action=get_record&id="+id, function(data){
			eval("var row = "+data);
			for(var k in row) {
				$("#"+k).val(row[k]);
			}
		})
	}

	<?
	if( isset($_GET['in_call_panel']) ) {  // 接通弹屏的处理
	?>
	$(function() {
		init_customer('<?echo $_GET['telephone']?>'); 
		$("#cust_tel").val('<?echo $_GET['telephone']?>')
		$("#call_type").val('<?echo $_GET['call_type']?>')
		$("#cust_tel").attr('readonly', true);
		$("#call_tel").val("<?echo $_GET['call_tel']?>");
	});
	<?} else if( isset($_GET['id']) ) {?>  
		init_record('<?echo $_GET['id']?>');  // 正常修改呼叫记录
	<?}?>
</script>
</body>
</html>